package com.yjc.rabbitMQ.five;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.yjc.rabbitMQ.utils.RabbitMQUtils;

/**
 * @author shkstart
 * @create 2022-07-31 15:15
 */
public class ReceiveLogs02 {

    private static final String EXCHANG_NAME = "logs";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtils.getChannel();
//        channel.exchangeDeclare(EXCHANG_NAME, "fanout");

        String queue_name = channel.queueDeclare().getQueue();

        //进行交换机和队列的绑定操作
        channel.queueBind(queue_name, EXCHANG_NAME, "");

        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println("ReceiveLogs02接收到的信息是：" + new String(message.getBody(), "UTF-8"));
        };

        channel.basicConsume(queue_name, true, deliverCallback, (consumerTag) -> {
            System.out.println("接受数据过程中被中断取消~~");
        });
    }
}
